<template>
  <a v-if="orderNo" @click="handleOpenDetail">{{ orderNo }}</a>
  <PayOrderDetail @register="registerPayOrder"></PayOrderDetail>
  <RefundOrderDetail @register="registerRefundOrder"></RefundOrderDetail>
</template>
<script lang="ts" setup>
  import { ref, useAttrs } from 'vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useDrawer } from '/@/components/Drawer';
  import PayOrderDetail from '../payOrder/OrderDetail.vue';
  import RefundOrderDetail from '../refund/OrderDetail.vue';
  const emit = defineEmits(['register']);
  const attrs = useAttrs();
  const detailData = ref();
  const { createMessage } = useMessage();
  const props = defineProps({
    orderNo: { type: String },
  })

  const [registerPayOrder, { openDrawer: openPayOrderDetail }] = useDrawer();
  const [registerRefundOrder, { openDrawer: openRefundOrderDetail }] = useDrawer();
  const handleOpenDetail = () => {
    if (props.orderNo?.startsWith('R')) {
      openRefundOrderDetail(true, {
        record: {
          refundOrderId: props.orderNo
        }
      });
    } else if (props.orderNo?.startsWith('P')) {
      openPayOrderDetail(true, {
        record: {
          payOrderNo: props.orderNo
        }
      });
    } else {
      createMessage.warn(`无法识别的订单号 ${props.orderNo}`)
    }
  }
</script>

<style lang="less">

</style>